
const { pool } = require('../config/mysql')

const query = (sql, values = []) => new Promise((resolve, reject) => {
    pool.getConnection((err, connection) => {
        if(err){
            reject({
                code: 500,
                data: null,
                msg: err
            })
        } else {
            connection.query(sql, values, (err, results) => {
                err ? reject(err) : resolve({code: 200, data: results, msg: '成功'})
                connection.release();
            })
        }
    })
})

module.exports = query
